/**
 * 深拷贝
 * @param {*} target 
 * @param {*} cacheMap 
 */
function deepClone(target, cacheMap = new WeakMap()) {
    // 基础数据类型
    if(typeof target !== 'object' || target == null) {
        return target;
    }

    // Date, RegExp
    if (target instanceof Date) {
        return new Date(target.now());
    }
    if (target instanceof RegExp) {
        return new RegExp(target);
    }

    // 循环引用
    if (cacheMap.has(target)) {
        return cacheMap.get(target);
    }

    const newTarget = new target.constructor();

    cacheMap.set(target, newTarget);

    for(const key in target) {
        if (target.hasOwnProperty(key)) {
            newTarget[key] = deepClone(target[key]);
        }
    }

    return newTarget;
}